package com.dongdongshop.consumer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.service.ElasticsearchService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RocketMQMessageListener(topic = "ddItemPage", consumerGroup = "dd", messageModel = MessageModel.BROADCASTING)
public class EsConsumer implements RocketMQListener<Long[]> {

    private static final Logger logger = LoggerFactory.getLogger(EsConsumer.class);

    @Reference
    private ElasticsearchService elasticsearchService;

    @Override
    public void onMessage(Long[] ids) {
        try {
            elasticsearchService.insertElasticsearch(ids);
            logger.info("消费成功");
        } catch (IOException e) {
            logger.error("消费失败",e);
        }
    }
}
